package cn.dg.manager.common.entity;

import java.io.Serializable;
import java.util.List;

import org.apache.poi.ss.formula.functions.T;

public class Page<T> implements Serializable {

	// 画面显示记录数
	private int pageSize = 20;
	
	private long totalCount;
	private int totalRow;
	private int pageNumber = 1;
	private Object parameter;
	private List<T> result;

	public Page() {}

	public Page(int pageSize)  
    {  
      if (pageSize < 1) {  
        this.pageSize = 20;  
      } else {  
        this.pageSize = pageSize;  
      }  
      this.pageNumber = 1;  
    }

	public int getPageSize() {
		return this.pageSize;
	}

	public int getTotalRow() {
		return this.totalRow;
	}

	public long getTotalCount() {
		return this.totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
		this.totalRow = ((int) (this.totalCount / this.pageSize + (this.totalCount % this.pageSize == 0L ? 0 : 1)));
	}

	public int getPageNumber() {
		return this.pageNumber <= 0 ? 1 : this.pageNumber;
	}

	public void setPageNumber(int page) {
		if (page < 1) {
			this.pageNumber = 1;
			return;
		}
		this.pageNumber = page;
	}

	public Object getParameter() {
		return this.parameter;
	}

	public void setParameter(Object parameter) {
		this.parameter = parameter;
	}

	public List<T> getResult() {
		return this.result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}


	public String toString() {
		return "pageSize:" + this.pageSize + ",totalCount:" + this.totalCount + ",totalPage:" + this.totalRow
				+ ",page:" + this.pageNumber;
	}

	/**
	 * @param totalRow the totalRow to set
	 */
	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
